package com.itheima.config;

import com.itheima.commons.JacksonObjectMapper;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;


import java.util.List;

//@Configuration
public class MvcConfig extends WebMvcConfigurationSupport {

    //由于js只能保证前16位数字的精度,超过后处理数字就会丢失精度
    //添加扩展mvc消息转化器,处理json数据格式转化
    @Override
    protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
        //创建消息转化器对象
        MappingJackson2HttpMessageConverter messageConverter=new MappingJackson2HttpMessageConverter();
        //设置对象转化器,底层使用jackson转化器将java对象序列化为json
        messageConverter.setObjectMapper(new JacksonObjectMapper());
        //将添加的消息转器对象添加到mvc框架的转化器集合中,设置到最前面,优先使用
        converters.add(0,messageConverter);
    }

}
